home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume20 / reactivekbd / part04 < prev    next >
Encoding:
Internet Message Format  |  1989-10-16  |  38.1 KB

  1. Subject:  v20i032:  Command-line editor with predictions, Part04/04
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: Mark James <jamesm@cpsc.UCalgary.CA>
  7. Posting-number: Volume 20, Issue 32
  8. Archive-name: reactivekbd/part04
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 4 (of 4)."
  17. # Contents:  functions.c
  18. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  19. if test -f 'functions.c' -a "${1}" != "-c" ; then 
  20.   echo shar: Will not clobber existing file \"'functions.c'\"
  21. else
  22. echo shar: Extracting \"'functions.c'\" \(35838 characters\)
  23. sed "s/^X//" >'functions.c' <<'END_OF_FILE'
  24. X#include "file+rk.h"
  25. X#include "rk_button.h"
  26. X#include <sys/ioctl.h>
  27. X#include <stdio.h>
  28. X
  29. Xextern char *cursor_left, *cursor_right;
  30. Xextern char *enter_insert_mode, *exit_insert_mode;
  31. Xextern char *pre_insert_char, *post_insert_char;
  32. Xextern char *enter_delete_mode, *exit_delete_mode, *delete_a_char;
  33. Xextern char *clear_screen;
  34. Xextern char *enter_standout_mode, *exit_standout_mode;    /* JJD 9-86 */
  35. Xextern int  current_key_map;
  36. Xextern char meta_prefixes[MAXEXTENSIONS][MAXEXTENSIONS];
  37. Xextern int  meta_map[MAXEXTENSIONS][MAXEXTENSIONS];
  38. X
  39. Xextern pred_number;
  40. Xextern pty_master;
  41. Xextern char output_string[],temp_str[];
  42. Xextern output_string_length;
  43. Xextern char pred_mode,pred_on_display,lisp_mode,nl_truncate_mode,eol_only_mode,eol_longer_mode,add_space_mode,show_eol_mode;
  44. Xextern char pred_buff[];
  45. Xextern (*keymap[128][MAXEXTENSIONS]) ();
  46. Xextern char trace_mode;
  47. Xextern struct sgttyb   new_stdin, old_stdin;
  48. Xextern int maxk;
  49. Xextern int maxprime;
  50. Xextern max_freq;
  51. Xextern max_nodes;
  52. X
  53. Xappend_to_output_string(c)
  54. X    char            c;
  55. X{
  56. X    output_string[output_string_length++] = c;
  57. X}
  58. X
  59. Xint 
  60. Xaccept_forward_word(e)
  61. X    ED_STRUCT      *e;
  62. X{                /* JJD 9-86 */
  63. X    char           *ch;
  64. X    int             how_many, num_to_advance;
  65. X
  66. X    if (!pred_mode)
  67. X        return forward_word(e);
  68. X    how_many = e->universal_argument;
  69. X    num_to_advance = 0;
  70. X    /* truncate prediction to after first NL */
  71. X    if (ch = index(pred_buff, '\n'))
  72. X        *(++ch) = '\0';
  73. X    ch = &pred_buff[0];    /* changed from editor data */
  74. X
  75. X    while (how_many--) {
  76. X        if ((!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  77. X            while (*ch && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  78. X                num_to_advance++, ch++;
  79. X
  80. X        while (*ch && (isalnum(*ch) || (*ch == '-') || (*ch == '_')))
  81. X            num_to_advance++, ch++;
  82. X        if(isspace(*ch)&&add_space_mode&&(*ch!='\n'))
  83. X            num_to_advance++, ch++;
  84. X        if (*ch == '\0')
  85. X            how_many = 0;
  86. X    }
  87. X
  88. X    e->universal_argument = num_to_advance;
  89. X    return accept_forward_char(e);    
  90. X}
  91. X
  92. Xint BOGUS(e)
  93. X    ED_STRUCT      *e;
  94. X{
  95. X        e->universal_argument = 1;
  96. X        write (1, "\07", 1);
  97. X        return(OK);
  98. X}
  99. X
  100. Xint 
  101. Xforward_word(e)
  102. X    ED_STRUCT      *e;
  103. X{
  104. X
  105. X    char           *ch;
  106. X    int             how_many, num_to_advance;
  107. X
  108. X    how_many = e->universal_argument;
  109. X    num_to_advance = 0;
  110. X    ch = e->dot;
  111. X
  112. X    while (how_many--) {
  113. X        if ((!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  114. X            while (*ch && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  115. X                num_to_advance++, ch++;
  116. X
  117. X        while (*ch && (isalnum(*ch) || (*ch == '-') || (*ch == '_')))
  118. X            num_to_advance++, ch++;
  119. X
  120. X        if (*ch == '\0')
  121. X            how_many = 0;
  122. X    }
  123. X
  124. X    e->universal_argument = num_to_advance;
  125. X    return forward_char(e);
  126. X}
  127. X
  128. X
  129. Xint 
  130. Xbackward_word(e)
  131. X    ED_STRUCT      *e;
  132. X{
  133. X
  134. X    char           *ch, *cb;
  135. X    int             num_to_go, how_many;
  136. X
  137. X    cb = e->current_buffer;
  138. X    ch = e->dot;
  139. X    num_to_go = 0;
  140. X    how_many = e->universal_argument;
  141. X
  142. X    if (ch-- == cb)
  143. X        return OK;
  144. X
  145. X    while (how_many--) {
  146. X        while ((ch >= cb) && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  147. X            num_to_go++, ch--;
  148. X
  149. X        while ((ch >= cb) &&
  150. X               (isalnum(*ch) ||
  151. X            (*ch == '-') ||
  152. X            (*ch == '_')))
  153. X            num_to_go++, ch--;
  154. X
  155. X        if (ch < e->current_buffer)
  156. X            how_many = 0;
  157. X    }
  158. X
  159. X    e->universal_argument = num_to_go;
  160. X    return backward_char(e);
  161. X}
  162. X
  163. X
  164. Xint 
  165. Xdelete_word(e)
  166. X    ED_STRUCT      *e;
  167. X{
  168. X
  169. X    char           *ch;
  170. X    int             how_many, num_to_advance;
  171. X
  172. X    how_many = e->universal_argument;
  173. X    num_to_advance = 0;
  174. X    ch = e->dot;
  175. X
  176. X    while (how_many--) {
  177. X        if ((!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  178. X            while (*ch && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  179. X                num_to_advance++, ch++;
  180. X
  181. X        while (*ch && (isalnum(*ch) || (*ch == '-') || (*ch == '_')))
  182. X            num_to_advance++, ch++;
  183. X
  184. X        if (*ch == '\0')
  185. X            how_many = 0;
  186. X    }
  187. X
  188. X    e->universal_argument = num_to_advance;
  189. X    return delete_char(e);
  190. X}
  191. X
  192. X
  193. Xint 
  194. Xbackspace_word(e)
  195. X    ED_STRUCT      *e;
  196. X{
  197. X
  198. X    char           *ch, *cb;
  199. X    int             num_to_go, how_many;
  200. X
  201. X    cb = e->current_buffer;
  202. X    ch = e->dot;
  203. X    num_to_go = 0;
  204. X    how_many = e->universal_argument;
  205. X
  206. X    if (ch-- == cb)
  207. X        return OK;
  208. X
  209. X    while (how_many--) {
  210. X        while ((ch >= cb) && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  211. X            num_to_go++, ch--;
  212. X
  213. X        while ((ch >= cb) &&
  214. X               (isalnum(*ch) ||
  215. X            (*ch == '-') ||
  216. X            (*ch == '_')))
  217. X            num_to_go++, ch--;
  218. X
  219. X        if (ch < e->current_buffer)
  220. X            how_many = 0;
  221. X    }
  222. X
  223. X    e->universal_argument = num_to_go;
  224. X    return backspace_char(e);
  225. X}
  226. X
  227. X
  228. Xint 
  229. Xforward_paren(e)
  230. X    ED_STRUCT      *e;
  231. X{
  232. X
  233. X    char           *ch = e->dot - 1;    /* pretend to go back one */
  234. X    int             paren_count = 1;
  235. X    int             num_to_advance = 0;
  236. X
  237. X    while (*++ch && paren_count) {
  238. X        num_to_advance++;
  239. X        if (*ch == ')')
  240. X            paren_count--;    /* a ')' with no intervening ()'s */
  241. X        else if (*ch == '(')    /* search for ) matching this ( */
  242. X            while (*++ch && paren_count) {
  243. X                num_to_advance++;
  244. X                if (*ch == ')')
  245. X                    paren_count--;
  246. X                else if (*ch == '(')
  247. X                    paren_count++;
  248. X            }
  249. X    }
  250. X
  251. X    e->universal_argument = num_to_advance;
  252. X    return forward_char(e);
  253. X}
  254. X
  255. X
  256. Xint 
  257. Xbackward_paren(e)
  258. X    ED_STRUCT      *e;
  259. X{
  260. X
  261. X    char           *ch, *cb;
  262. X    int             paren_count = 1;
  263. X    int             num_to_go = 0;
  264. X
  265. X    ch = e->dot;
  266. X    cb = e->current_buffer;
  267. X
  268. X    if (ch != cb)        /* not already at the beginning */
  269. X        while ((--ch >= cb) && paren_count) {
  270. X            num_to_go++;
  271. X            if (*ch == '(')
  272. X                paren_count--;    /* a '(' with no intervening
  273. X                         * ()'s */
  274. X            else if (*ch == ')')    /* search for ( matching this
  275. X                         * ) */
  276. X                while ((--ch >= cb) && paren_count) {
  277. X                    num_to_go++;
  278. X                    if (*ch == '(')
  279. X                        paren_count--;
  280. X                    else if (*ch == ')')
  281. X                        paren_count++;
  282. X                }
  283. X        }
  284. X
  285. X    e->universal_argument = num_to_go;
  286. X    return backward_char(e);
  287. X}
  288. X
  289. Xint 
  290. Xtoggle_lisp_mode(e)
  291. X    ED_STRUCT      *e;
  292. X{
  293. X    lisp_mode = !lisp_mode;
  294. X    return OK;
  295. X}
  296. X
  297. Xint 
  298. Xtoggle_add_space_mode(e)
  299. X    ED_STRUCT      *e;
  300. X{
  301. X    add_space_mode = !add_space_mode;
  302. X    return OK;
  303. X}
  304. X
  305. Xint 
  306. Xtoggle_show_eol_mode(e)
  307. X    ED_STRUCT      *e;
  308. X{
  309. X    show_eol_mode = !show_eol_mode;
  310. X    if (pred_on_display)
  311. X        erase_pred_buffer(e);
  312. X    if (pred_mode)
  313. X        make_a_prediction(pred_buff);
  314. X    return OK;
  315. X}
  316. X
  317. Xint 
  318. Xtoggle_nl_truncate_mode(e)
  319. X    ED_STRUCT      *e;
  320. X{                /* JJD 9-86 */
  321. X    nl_truncate_mode = !nl_truncate_mode;
  322. X    if (pred_on_display)
  323. X        erase_pred_buffer(e);
  324. X    if (pred_mode)
  325. X        make_a_prediction(pred_buff);
  326. X    return OK;
  327. X}
  328. X
  329. Xint 
  330. Xtoggle_eol_only_mode(e)
  331. X    ED_STRUCT      *e;
  332. X{                /* JJD 9-86 */
  333. X    eol_only_mode = !eol_only_mode;
  334. X    if (pred_on_display)
  335. X        erase_pred_buffer(e);
  336. X    if (pred_mode)
  337. X        make_a_prediction(pred_buff);
  338. X    return OK;
  339. X}
  340. X
  341. Xint 
  342. Xtoggle_eol_longer_mode(e)
  343. X    ED_STRUCT      *e;
  344. X{                /* JJD 9-86 */
  345. X    eol_longer_mode = !eol_longer_mode;
  346. X    if (pred_on_display)
  347. X        erase_pred_buffer(e);
  348. X    if (pred_mode)
  349. X        make_a_prediction(pred_buff);
  350. X    return OK;
  351. X}
  352. X
  353. Xint 
  354. Xtoggle_pred_mode(e)
  355. X    ED_STRUCT      *e;
  356. X{                /* JJD 9-86 */
  357. X    pred_mode = !pred_mode;
  358. X    if (pred_on_display)
  359. X        erase_pred_buffer(e);
  360. X    if (pred_mode)
  361. X        make_a_prediction(pred_buff);
  362. X    return OK;
  363. X}
  364. X
  365. Xint 
  366. Xshow_free_nodes(e)
  367. X    ED_STRUCT      *e;
  368. X{                /* JJD 1-87, revised 3-89 */
  369. X    extern int      next_free;
  370. X    char            tbuf[128];    /* extern in rk_button */
  371. X    extern long     psize;
  372. X    sprintf(tbuf, "\015\nK=%d, COUNT=%d, NODES=%d, PRIME=%d; psize=%d, nodes=%d\015\n",
  373. X        maxk, max_freq, max_nodes, maxprime, psize, next_free);
  374. X    write(1, tbuf, strlen(tbuf));
  375. X    write(1, "Continue: ", 10);    /* JJD 3-89 added */
  376. X    draw_current_edit_line(e);    /* JJD 3-89 added */
  377. X    return OK;
  378. X}
  379. X
  380. Xint 
  381. Xshow_version(e)
  382. X    ED_STRUCT      *e;
  383. X{                /* JJD 3-89 added */
  384. X    char            tbuf[128];
  385. X    sprintf(tbuf, "\015\nRK_Button Version: %s", RK_VERSION);
  386. X    strcat(tbuf, ", with file_completion (^C).\015\n");
  387. X    write(1, tbuf, strlen(tbuf));
  388. X    write(1, "Continue: ", 10);
  389. X    draw_current_edit_line(e);
  390. X    return OK;
  391. X}
  392. X
  393. Xint 
  394. Xprime_from_file(e)
  395. X    ED_STRUCT      *e;
  396. X{                /* JJD 9-86 */
  397. X    char            filename[256];
  398. X    FILE           *from;
  399. X    int             i;
  400. X    char            c;
  401. X    extern Buffer   Buf;    /* externs in rk_button */
  402. X    extern char     context[MAX_CMD_LINE_LENGTH];
  403. X
  404. X    erase_current_edit_line(e);
  405. X    e->dot = e->current_buffer;
  406. X    e->mark = e->current_buffer;
  407. X    *(e->dot) = '\0';
  408. X
  409. X    ioctl(0, TIOCGETP, &new_stdin);
  410. X    ioctl(0, TIOCSETP, &old_stdin);
  411. X    strcpy(filename, "");
  412. X    printf("File to prime from ([RETURN] to cancel): ");
  413. X    fflush(stdout);
  414. X    gets(filename);
  415. X    if (filename[0] == '\0') {
  416. X        printf("Command cancelled.\r\n");
  417. X        fflush(stdout);
  418. X    } else {
  419. X        if ((from = fopen(filename, "r")) == NULL) {
  420. X            printf("cannot open: %s\r\n", filename);
  421. X            fflush(stdout);
  422. X        } else {
  423. X            while (((int) (c = getc(from))) != EOF)
  424. X                for (i = maxk; i > 0; i--)
  425. X                    Buf[i] = move_up(Buf[i - 1], c);
  426. X            fclose(from);
  427. X            show_free_nodes(e);
  428. X        }
  429. X    }
  430. X    ioctl(0, TIOCSETP, &new_stdin);
  431. X
  432. X    return OK;
  433. X}
  434. X
  435. X
  436. Xint 
  437. Xclose_paren(e)
  438. X    ED_STRUCT      *e;
  439. X{
  440. X
  441. X    char           *old_dot;
  442. X
  443. X    if (!lisp_mode)
  444. X        return self_insert(e);
  445. X
  446. X    old_dot = e->dot;
  447. X    if (*old_dot != ')')    /* if not on a ')', insert one */
  448. X        self_insert(e);
  449. X
  450. X    forward_char(e);    /* skip past ')' so bkd-prn works */
  451. X    backward_paren(e);    /* flash back to matching '(' */
  452. X    sleep(1);
  453. X
  454. X    e->universal_argument = 1 + old_dot - e->dot;
  455. X    return forward_char(e);    /* skip ahead to old dot + 1 */
  456. X}
  457. X
  458. X
  459. Xint 
  460. Xopen_paren(e)
  461. X    ED_STRUCT      *e;
  462. X{
  463. X
  464. X    char           *old_dot;
  465. X
  466. X    self_insert(e);        /* stick in an open_paren */
  467. X    if (!lisp_mode)
  468. X        return OK;
  469. X
  470. X    old_dot = e->dot;
  471. X    if ((*old_dot == ')') || (*old_dot == 0)) {
  472. X        e->current_input_char = ')';    /* if on a ')' or at the end */
  473. X        self_insert(e);    /* then insert matching ')' */
  474. X        backward_char(e);    /* and go back inside () */
  475. X    }
  476. X    return OK;
  477. X}
  478. X
  479. X
  480. Xint 
  481. Xincrement_universal_argument(e)
  482. X    ED_STRUCT      *e;
  483. X{
  484. X
  485. X    if (e->universal_argument > UNIVERSAL_ARGUMENT_MAXIMUM)
  486. X        write(1, "\07", 1);
  487. X    else
  488. X        e->universal_argument *= 4;
  489. X
  490. X    return OK;
  491. X}
  492. X
  493. X
  494. Xint 
  495. Xclear_display(e)
  496. X    ED_STRUCT      *e;
  497. X{
  498. X
  499. X    e->universal_argument = 1;
  500. X    output_string_length = 0;
  501. X    if (clear_screen) {
  502. X        tputs(clear_screen, ONE_LINE, append_to_output_string);
  503. X        write(1, output_string, output_string_length);
  504. X    } else
  505. X        write(1, "\r\n\r\n", 2);
  506. X    draw_current_edit_line(e);
  507. X
  508. X    return OK;
  509. X}
  510. X
  511. X
  512. X
  513. Xint 
  514. Xprevious_line(e)
  515. X    ED_STRUCT      *e;
  516. X{
  517. X
  518. X    int             how_many;
  519. X
  520. X    how_many = e->universal_argument;
  521. X    e->current_ed_buff_ptr->dot = e->dot;
  522. X    e->current_ed_buff_ptr->mark = e->mark;
  523. X    erase_current_edit_line(e);
  524. X    for (; how_many; --how_many)
  525. X        e->current_ed_buff_ptr = e->current_ed_buff_ptr->prev_ptr;
  526. X    e->current_buffer = e->current_ed_buff_ptr->string;
  527. X    e->dot = e->current_ed_buff_ptr->dot;
  528. X    e->mark = e->current_ed_buff_ptr->mark;
  529. X    draw_current_edit_line(e);
  530. X    e->universal_argument = 1;
  531. X    return OK;
  532. X}
  533. X
  534. X
  535. Xint 
  536. Xprevious_pred(e)
  537. X    ED_STRUCT      *e;
  538. X{                /* JJD 9-86 */
  539. X
  540. X    if (pred_number)
  541. X        pred_number--;
  542. X    return OK;
  543. X}
  544. X
  545. Xint 
  546. Xnext_pred(e)
  547. X    ED_STRUCT      *e;
  548. X{                /* JJD 9-86 */
  549. X
  550. X    if (++pred_number > 127)
  551. X        pred_number = 127;
  552. X    return OK;
  553. X}
  554. X
  555. Xint 
  556. Xnext_line(e)
  557. X    ED_STRUCT      *e;
  558. X{
  559. X
  560. X    int             how_many;
  561. X
  562. X    how_many = e->universal_argument;
  563. X    e->current_ed_buff_ptr->dot = e->dot;
  564. X
  565. X    e->current_ed_buff_ptr->mark = e->mark;
  566. X
  567. X    erase_current_edit_line(e);
  568. X    for (; how_many; --how_many)
  569. X        e->current_ed_buff_ptr = e->current_ed_buff_ptr->next_ptr;
  570. X    e->current_buffer = e->current_ed_buff_ptr->string;
  571. X    e->dot = e->current_ed_buff_ptr->dot;
  572. X
  573. X    e->mark = e->current_ed_buff_ptr->mark;
  574. X
  575. X    draw_current_edit_line(e);
  576. X    e->universal_argument = 1;
  577. X    return OK;
  578. X}
  579. X
  580. X
  581. Xint 
  582. Xdiscard_current_edit_line(e)
  583. X    ED_STRUCT      *e;
  584. X{
  585. X
  586. X    strcpy(e->kill_buffer, e->current_buffer);
  587. X    erase_current_edit_line(e);
  588. X    e->dot = e->current_buffer;
  589. X
  590. X    e->mark = e->current_buffer;
  591. X
  592. X    *e->dot = '\0';
  593. X
  594. X    return OK;
  595. X}
  596. X
  597. X
  598. Xint 
  599. Xdiscard_rest_of_line(e)
  600. X    ED_STRUCT      *e;
  601. X{
  602. X
  603. X    strcpy(e->kill_buffer, e->dot);
  604. X    e->universal_argument = strlen(e->dot);
  605. X
  606. X    if (e->universal_argument == 0) {
  607. X        e->universal_argument = 1;
  608. X        return OK;
  609. X    } else
  610. X
  611. X    {
  612. X        if (e->mark > e->dot)
  613. X            e->mark = e->dot;
  614. X        return delete_char(e);
  615. X    }
  616. X
  617. X}
  618. X
  619. X
  620. Xint 
  621. Xyank_from_kill_buffer(e)
  622. X    ED_STRUCT      *e;
  623. X{
  624. X
  625. X    int             count;
  626. X
  627. X    output_string_length = 0;
  628. X    strcpy(temp_str, e->dot);
  629. X    strcpy(e->dot, e->kill_buffer);
  630. X
  631. X    if (e->mark > e->dot)
  632. X        e->mark += strlen(e->kill_buffer);
  633. X
  634. X    e->dot = e->dot + strlen(e->kill_buffer);
  635. X    strcpy(e->dot, temp_str);
  636. X    display_string_into_output_string(e->kill_buffer);
  637. X    count = display_string_into_output_string(temp_str);
  638. X    for (; count; --count)
  639. X        tputs(cursor_left, ONE_LINE, append_to_output_string);
  640. X    write(1, output_string, output_string_length);
  641. X
  642. X    return OK;
  643. X}
  644. X
  645. X
  646. X
  647. Xint 
  648. Xdisplay_pred_buffer(e)
  649. X    ED_STRUCT      *e;
  650. X{                /* JJD 9-86 ???? */
  651. X
  652. X    int             count;
  653. X
  654. X    output_string[0] = '\0';
  655. X    output_string_length = 0;
  656. X
  657. X    if (enter_standout_mode)
  658. X        tputs(enter_standout_mode, ONE_LINE, append_to_output_string);
  659. X    count = display_string_into_output_string(pred_buff);
  660. X    if (enter_standout_mode)
  661. X        tputs(exit_standout_mode, ONE_LINE, append_to_output_string);
  662. X    count += display_string_into_output_string(e->dot);
  663. X
  664. X    for (; count; --count)
  665. X        tputs(cursor_left, ONE_LINE, append_to_output_string);
  666. X    write(1, output_string, output_string_length);
  667. X    pred_on_display = 1;
  668. X
  669. X    return OK;
  670. X}
  671. X
  672. X
  673. Xint 
  674. Xerase_pred_buffer(e)
  675. X    ED_STRUCT      *e;
  676. X{                /* JJD 9-86 */
  677. X
  678. X    int             num_to_erase, count;
  679. X
  680. X    output_string[0] = '\0';
  681. X    output_string_length = 0;
  682. X
  683. X    if (enter_standout_mode)
  684. X        tputs(exit_standout_mode, ONE_LINE, append_to_output_string);
  685. X    display_string_into_output_string(e->dot);
  686. X
  687. X    num_to_erase = get_display_length(pred_buff);
  688. X    for (count = num_to_erase; count; --count)
  689. X        output_string[output_string_length++] = ' ';
  690. X    num_to_erase += get_display_length(e->dot);
  691. X    for (count = num_to_erase; count; --count)
  692. X        tputs(cursor_left, ONE_LINE, append_to_output_string);
  693. X    write(1, output_string, output_string_length);
  694. X    pred_on_display = 0;
  695. X
  696. X    return OK;
  697. X}
  698. X
  699. Xint 
  700. Xinsert_interrupt_char(e)
  701. X    ED_STRUCT      *e;
  702. X{
  703. X
  704. X    struct tchars   pty_tchars;
  705. X
  706. X    ioctl(pty_master, TIOCGETC, &pty_tchars);
  707. X
  708. X    erase_current_edit_line(e);
  709. X    e->dot = e->current_buffer;
  710. X
  711. X    e->mark = e->current_buffer;
  712. X
  713. X    *(e->dot++) = pty_tchars.t_intrc;
  714. X    *(e->dot) = '\0';
  715. X    return FINISHED_BUT_DONT_ADD_CTRL_M;
  716. X}
  717. X
  718. Xint 
  719. Xinsert_quit_char(e)
  720. X    ED_STRUCT      *e;
  721. X{
  722. X
  723. X    struct tchars   pty_tchars;
  724. X
  725. X    ioctl(pty_master, TIOCGETC, &pty_tchars);
  726. X
  727. X    erase_current_edit_line(e);
  728. X    e->dot = e->current_buffer;
  729. X    e->mark = e->current_buffer;
  730. X    *(e->dot++) = pty_tchars.t_quitc;
  731. X    *(e->dot) = '\0';
  732. X    return FINISHED_BUT_DONT_ADD_CTRL_M;
  733. X}
  734. X
  735. Xint 
  736. Xinsert_stop_char(e)
  737. X    ED_STRUCT      *e;
  738. X{                /* JJD 9-86 */
  739. X
  740. X    struct tchars   pty_tchars;
  741. X
  742. X    ioctl(pty_master, TIOCGETC, &pty_tchars);
  743. X
  744. X    erase_current_edit_line(e);
  745. X    e->dot = e->current_buffer;
  746. X    e->mark = e->current_buffer;
  747. X    *(e->dot++) = pty_tchars.t_stopc;
  748. X    *(e->dot) = '\0';
  749. X    return FINISHED_BUT_DONT_ADD_CTRL_M;
  750. X}
  751. X
  752. Xint 
  753. Xinsert_start_char(e)
  754. X    ED_STRUCT      *e;
  755. X{                /* JJD 9-86 */
  756. X
  757. X    struct tchars   pty_tchars;
  758. X
  759. X    ioctl(pty_master, TIOCGETC, &pty_tchars);
  760. X
  761. X    erase_current_edit_line(e);
  762. X    e->dot = e->current_buffer;
  763. X    e->mark = e->current_buffer;
  764. X    *(e->dot++) = pty_tchars.t_startc;
  765. X    *(e->dot) = '\0';
  766. X    return FINISHED_BUT_DONT_ADD_CTRL_M;
  767. X}
  768. X
  769. Xint 
  770. Xinsert_eof_char(e)
  771. X    ED_STRUCT      *e;
  772. X{                /* JJD 9-86 */
  773. X
  774. X    struct tchars   pty_tchars;
  775. X
  776. X    ioctl(pty_master, TIOCGETC, &pty_tchars);
  777. X
  778. X    erase_current_edit_line(e);
  779. X    e->dot = e->current_buffer;
  780. X    e->mark = e->current_buffer;
  781. X    *(e->dot++) = pty_tchars.t_eofc;
  782. X    *(e->dot) = '\0';
  783. X    return FINISHED_BUT_DONT_ADD_CTRL_M;
  784. X}
  785. X
  786. Xint 
  787. Xinsert_suspend_char(e)
  788. X    ED_STRUCT      *e;
  789. X{
  790. X
  791. X    struct ltchars  pty_ltchars;
  792. X
  793. X    ioctl(pty_master, TIOCGLTC, &pty_ltchars);
  794. X
  795. X    erase_current_edit_line(e);
  796. X    e->dot = e->current_buffer;
  797. X    e->mark = e->current_buffer;
  798. X    *(e->dot++) = pty_ltchars.t_suspc;
  799. X    *(e->dot) = '\0';
  800. X    return FINISHED_BUT_DONT_ADD_CTRL_M;
  801. X}
  802. X
  803. X
  804. X
  805. Xint 
  806. Xtwiddle_chars(e)
  807. X    ED_STRUCT      *e;
  808. X{
  809. X
  810. X    char            temp_char;
  811. X    int             num_to_back_up, count;
  812. X
  813. X    output_string_length = 0;
  814. X
  815. X    if (strlen(e->current_buffer) == 0) {
  816. X        *e->dot++ = '\024';
  817. X        *e->dot = '\0';
  818. X        return FINISHED_BUT_DONT_ADD_CTRL_M;
  819. X    } else if ((e->dot - e->current_buffer) < 2)
  820. X        write(1, "\07", 1);
  821. X    else {
  822. X        temp_char = *(e->dot - 1);
  823. X        *(e->dot - 1) = *(e->dot - 2);
  824. X        *(e->dot - 2) = temp_char;
  825. X        num_to_back_up = get_char_display_length(*(e->dot - 2));
  826. X        num_to_back_up += get_char_display_length(*(e->dot - 1));
  827. X        for (count = num_to_back_up; count; --count)
  828. X            tputs(cursor_left, ONE_LINE, append_to_output_string);
  829. X        display_char_into_output_string(*(e->dot - 2));
  830. X        display_char_into_output_string(*(e->dot - 1));
  831. X        write(1, output_string, output_string_length);
  832. X    }
  833. X
  834. X    e->universal_argument = 1;
  835. X
  836. X    return OK;
  837. X}
  838. X
  839. Xint 
  840. Xbeginning_of_line(e)
  841. X    ED_STRUCT      *e;
  842. X{
  843. X
  844. X    e->universal_argument = 1;
  845. X    output_string[0] = '\0';
  846. X    output_string_length = 0;
  847. X    while (e->dot != e->current_buffer) {
  848. X        e->dot--;
  849. X        if ((*(e->dot) < 32) || (*(e->dot) == 127)) {
  850. X            tputs(cursor_left, ONE_LINE, append_to_output_string);
  851. X            tputs(cursor_left, ONE_LINE, append_to_output_string);
  852. X        } else
  853. X            tputs(cursor_left, ONE_LINE, append_to_output_string);
  854. X    }
  855. X
  856. X    write(1, output_string, output_string_length);
  857. X
  858. X    return OK;
  859. X}
  860. X
  861. Xint 
  862. Xend_of_line(e)
  863. X    ED_STRUCT      *e;
  864. X{
  865. X
  866. X    e->universal_argument = 1;
  867. X    output_string[0] = '\0';
  868. X    output_string_length = 0;
  869. X    display_string_into_output_string(e->dot);
  870. X    e->dot = &(e->current_buffer[strlen(e->current_buffer)]);
  871. X
  872. X    write(1, output_string, output_string_length);
  873. X
  874. X    return OK;
  875. X}
  876. X
  877. Xint 
  878. Xquote_char(e)
  879. X    ED_STRUCT      *e;
  880. X{
  881. X
  882. X    char            quoted_char;
  883. X
  884. X    READ(0, "ed_char, 1);
  885. X    quoted_char &= 127;
  886. X    if (quoted_char == '\0') {
  887. X        write(1, "\07", 1);
  888. X        return OK;
  889. X    } else {
  890. X        e->current_input_char = quoted_char;
  891. X        return self_insert(e);
  892. X    }
  893. X}
  894. X
  895. Xmeta_prefix(e)
  896. X    ED_STRUCT      *e;
  897. X{
  898. X    char            metad_char;
  899. X    int        i=0;
  900. X    int        status;
  901. X
  902. X    if(e==0)
  903. X        abortit("meta_prefix passed a nil pointer, aborting...\n",-1);
  904. X
  905. X    while((i<MAXEXTENSIONS) && (meta_prefixes[i][current_key_map]) &&
  906. X          (e->current_input_char!=meta_prefixes[i][current_key_map]))
  907. X        i++;
  908. X    if(i==MAXEXTENSIONS)
  909. X        return(BOGUS(e));
  910. X    current_key_map=meta_map[i][current_key_map];
  911. X
  912. X    if (pred_mode && pred_buff[0] && !pred_on_display)
  913. X        display_pred_buffer(e);    /* JJD 9-86 */
  914. X    READ(0, &metad_char, 1);
  915. X    if (pred_on_display) erase_pred_buffer (e);    /* JJD 3-89 added */
  916. X    metad_char &= 127;    /* clear high bit */
  917. X    e->current_input_char = metad_char;
  918. X    status  = (keymap[(int) metad_char][current_key_map])(e);
  919. X    current_key_map=0;
  920. X    return(status);
  921. X}
  922. X
  923. X
  924. X    
  925. X
  926. X
  927. Xint 
  928. Xbackward_char(e)
  929. X    ED_STRUCT      *e;
  930. X{
  931. X
  932. X    int             num_to_go, count, needs_beep;
  933. X
  934. X    output_string[0] = '\0';
  935. X    output_string_length = 0;
  936. X
  937. X    if ((e->dot - e->universal_argument) < e->current_buffer)
  938. X        num_to_go = e->dot - e->current_buffer, needs_beep = 1;
  939. X    else
  940. X        num_to_go = e->universal_argument, needs_beep = 0;
  941. X
  942. X    count = num_to_go;
  943. X    while (count-- > 0) {
  944. X        e->dot--;
  945. X        tputs(cursor_left, ONE_LINE, append_to_output_string);
  946. X        if ((*(e->dot) < 32) || (*(e->dot) == 127))
  947. X            tputs(cursor_left, ONE_LINE, append_to_output_string);
  948. X    }
  949. X
  950. X    if (needs_beep)
  951. X        output_string[output_string_length++] = '\07';
  952. X
  953. X    write(1, output_string, output_string_length);
  954. X
  955. X    e->universal_argument = 1;
  956. X
  957. X    return OK;
  958. X}
  959. X
  960. Xint 
  961. Xaccept_to_end_of_line(e)
  962. X    ED_STRUCT      *e;
  963. X{                /* JJD 9-86 */
  964. X
  965. X    char           *ptr;
  966. X
  967. X    if (!pred_mode)
  968. X        return end_of_line(e);
  969. X    /* truncate prediction to after first NL */
  970. X    if (ptr = index(pred_buff, '\n')){
  971. X        *(++ptr) = '\0';
  972. X    }
  973. X    /* only go to end of prediction */
  974. X    e->universal_argument = strlen(pred_buff);
  975. X    return accept_forward_char(e);
  976. X}
  977. X
  978. Xint 
  979. Xaccept_forward_char(e)
  980. X    ED_STRUCT      *e;
  981. X{                /* JJD 9-86 */
  982. X
  983. X    int             num_to_go, count, needs_beep, finished = 0;
  984. X
  985. X    if (!pred_mode)
  986. X        return forward_char(e);
  987. X    if (pred_buff[0] == '\n')
  988. X        return finish_editing_line(e);
  989. X    output_string[0] = '\0';
  990. X    output_string_length = 0;
  991. X
  992. X    num_to_go = strlen(pred_buff);
  993. X    if (e->universal_argument > num_to_go)    /* to end of prediction */
  994. X        needs_beep = 1;
  995. X    else
  996. X        num_to_go = e->universal_argument, needs_beep = 0;
  997. X
  998. X    /* there is at most 1 NL at the end of the prediction */
  999. X    if (pred_buff[num_to_go - 1] == '\n') {
  1000. X        num_to_go--;
  1001. X        finished = 1;
  1002. X    }
  1003. X    pred_buff[num_to_go] = '\0';
  1004. X    display_string_into_output_string(pred_buff);
  1005. X    strcat(pred_buff, e->dot);
  1006. X    strcpy(e->dot, pred_buff);
  1007. X    if (e->mark > e->dot)
  1008. X        e->mark += num_to_go;
  1009. X    e->dot += num_to_go;
  1010. X    count = display_string_into_output_string(e->dot);
  1011. X    for (; count; --count)
  1012. X        tputs(cursor_left, ONE_LINE, append_to_output_string);
  1013. X
  1014. X    if (needs_beep)
  1015. X        output_string[output_string_length++] = '\07';
  1016. X    write(1, output_string, output_string_length);
  1017. X    e->universal_argument = 1;
  1018. X
  1019. X    if (finished)
  1020. X        return finish_editing_line(e);
  1021. X    else
  1022. X        return OK;
  1023. X}
  1024. X
  1025. Xint 
  1026. Xforward_char(e)
  1027. X    ED_STRUCT      *e;
  1028. X{
  1029. X
  1030. X    int             num_to_go, count, needs_beep;
  1031. X
  1032. X    output_string[0] = '\0';
  1033. X    output_string_length = 0;
  1034. X
  1035. X    if (e->universal_argument > strlen(e->dot))
  1036. X        num_to_go = strlen(e->dot), needs_beep = 1;
  1037. X    else
  1038. X        num_to_go = e->universal_argument, needs_beep = 0;
  1039. X
  1040. X    count = num_to_go;
  1041. X    while (count-- > 0)
  1042. X        display_char_into_output_string(*(e->dot++));
  1043. X
  1044. X    if (needs_beep)
  1045. X        output_string[output_string_length++] = '\07';
  1046. X
  1047. X    write(1, output_string, output_string_length);
  1048. X
  1049. X    e->universal_argument = 1;
  1050. X
  1051. X    return OK;
  1052. X}
  1053. X
  1054. X
  1055. Xint 
  1056. Xbackspace_char(e)
  1057. X    ED_STRUCT      *e;
  1058. X{
  1059. X
  1060. X    int             rest_of_line_display_length, count;
  1061. X    int             num_to_delete;
  1062. X    char           *c, *new_dot;
  1063. X    char           *old_dot = e->dot;    /* JJD 3-89 added */
  1064. X
  1065. X    output_string[0] = '\0';
  1066. X    output_string_length = 0;
  1067. X
  1068. X    if ((e->dot - e->current_buffer) < e->universal_argument)
  1069. X        new_dot = e->current_buffer;
  1070. X    else
  1071. X        new_dot = e->dot - e->universal_argument;
  1072. X
  1073. X    num_to_delete = 0;
  1074. X    for (c = e->dot - 1; c >= new_dot; --c)
  1075. X        if ((*c < 32) || (*c == 127))
  1076. X            num_to_delete += 2;
  1077. X        else
  1078. X            num_to_delete++;
  1079. X
  1080. X    if (delete_a_char) {
  1081. X        for (count = num_to_delete; count; --count)
  1082. X            tputs(cursor_left, ONE_LINE, append_to_output_string);
  1083. X
  1084. X        if (enter_delete_mode)
  1085. X            tputs(enter_delete_mode, ONE_LINE, append_to_output_string);
  1086. X
  1087. X        for (count = num_to_delete; count; --count)
  1088. X            tputs(delete_a_char, ONE_LINE, append_to_output_string);
  1089. X
  1090. X        if (enter_delete_mode)
  1091. X            tputs(exit_delete_mode, ONE_LINE, append_to_output_string);
  1092. X    } else {
  1093. X        for (count = num_to_delete; count; --count)
  1094. X            tputs(cursor_left, ONE_LINE, append_to_output_string);
  1095. X
  1096. X        rest_of_line_display_length =
  1097. X            display_string_into_output_string(e->dot);
  1098. X
  1099. X        for (count = num_to_delete; count; --count)
  1100. X            output_string[output_string_length++] = ' ';
  1101. X
  1102. X        for (count = num_to_delete + rest_of_line_display_length; count; --count)
  1103. X            tputs(cursor_left, ONE_LINE, append_to_output_string);
  1104. X    }
  1105. X
  1106. X    if (e->dot - e->universal_argument < e->current_buffer)
  1107. X        output_string[output_string_length++] = '\07';
  1108. X
  1109. X    strcpy(temp_str, e->dot);
  1110. X    strcpy(new_dot, temp_str);
  1111. X    e->dot = new_dot;
  1112. X    if (e->mark >= new_dot)
  1113. X        e->mark -= (old_dot - new_dot);
  1114. X    e->universal_argument = 1;
  1115. X    write(1, output_string, output_string_length);
  1116. X
  1117. X    return OK;
  1118. X}
  1119. X
  1120. Xint 
  1121. Xdelete_char(e)
  1122. X    ED_STRUCT      *e;
  1123. X{
  1124. X
  1125. X    int             count;
  1126. X    int             num_to_delete, num_to_back_up;
  1127. X    char           *c, *new_dot;
  1128. X    char           *old_dot = e->dot;    /* JJD 3-89 added */
  1129. X
  1130. X    if (*(e->dot) == '\0') {
  1131. X        struct tchars   pty_tchars;
  1132. X        ioctl(pty_master, TIOCGETC, &pty_tchars);
  1133. X        erase_pred_buffer(e);
  1134. X        erase_current_edit_line(e);
  1135. X        *(e->dot++) = pty_tchars.t_eofc;
  1136. X        *(e->dot) = '\0';
  1137. X        return FINISHED_BUT_DONT_ADD_CTRL_M;
  1138. X    }
  1139. X    output_string[0] = '\0';
  1140. X    output_string_length = 0;
  1141. X
  1142. X    if (e->universal_argument > strlen(e->dot))
  1143. X        new_dot = e->dot + strlen(e->dot);
  1144. X    else
  1145. X        new_dot = e->dot + e->universal_argument;
  1146. X
  1147. X    num_to_delete = 0;
  1148. X    for (c = e->dot; c < new_dot; ++c)
  1149. X        if ((*c < 32) || (*c == 127))
  1150. X            num_to_delete += 2;
  1151. X        else
  1152. X            num_to_delete++;
  1153. X
  1154. X    if (delete_a_char) {
  1155. X        if (enter_delete_mode)
  1156. X            tputs(enter_delete_mode, ONE_LINE, append_to_output_string);
  1157. X
  1158. X        for (count = num_to_delete; count; --count)
  1159. X            tputs(delete_a_char, ONE_LINE, append_to_output_string);
  1160. X
  1161. X        if (enter_delete_mode)
  1162. X            tputs(exit_delete_mode, ONE_LINE, append_to_output_string);
  1163. X    } else {
  1164. X        num_to_back_up = display_string_into_output_string(new_dot);
  1165. X        for (count = num_to_delete; count; --count)
  1166. X            output_string[output_string_length++] = ' ';
  1167. X        for (count = num_to_back_up + num_to_delete; count; --count)
  1168. X            tputs(cursor_left, ONE_LINE, append_to_output_string);
  1169. X    }
  1170. X
  1171. X    if (e->universal_argument > strlen(e->dot))
  1172. X        output_string[output_string_length++] = '\07';
  1173. X
  1174. X    strcpy(temp_str, new_dot);
  1175. X    strcpy(e->dot, temp_str);
  1176. X    e->universal_argument = 1;
  1177. X    if (e->mark >= new_dot)
  1178. X        e->mark += (old_dot - new_dot);
  1179. X    write(1, output_string, output_string_length);
  1180. X
  1181. X    return OK;
  1182. X}
  1183. X
  1184. X
  1185. Xint 
  1186. Xfinish_editing_line(e)
  1187. X    ED_STRUCT      *e;
  1188. X{
  1189. X
  1190. X    char           *old_dot;
  1191. X
  1192. X    e->universal_argument = 1;
  1193. X    old_dot = e->dot;
  1194. X    beginning_of_line(e);
  1195. X    e->dot = old_dot;    /* necessary to preserve cursor position
  1196. X                 * accross newlines                      */
  1197. X    return FINISHED_EDITING;
  1198. X}
  1199. X
  1200. X
  1201. Xint 
  1202. Xself_insert(e)
  1203. X    ED_STRUCT      *e;
  1204. X{
  1205. X
  1206. X    int             num_to_back_up, count;
  1207. X    char           *old_dot = e->dot;    /* JJD 3-89 added */
  1208. X
  1209. X    strcpy(output_string, "");
  1210. X    output_string_length = 0;
  1211. X
  1212. X    if (*(e->dot) == '\0') {
  1213. X        for (count = e->universal_argument; count; --count)
  1214. X            display_char_into_output_string(e->current_input_char);
  1215. X    } else {
  1216. X        if (enter_insert_mode || pre_insert_char) {
  1217. X            if (enter_insert_mode)
  1218. X                tputs(enter_insert_mode, ONE_LINE, append_to_output_string);
  1219. X
  1220. X            for (count = e->universal_argument; count; --count) {
  1221. X                if (pre_insert_char)
  1222. X                    tputs(pre_insert_char, ONE_LINE, append_to_output_string);
  1223. X                if ((e->current_input_char < 32)) {
  1224. X                    output_string[output_string_length++] = '^';
  1225. X                    if (post_insert_char)
  1226. X                        tputs(post_insert_char, ONE_LINE,
  1227. X                           append_to_output_string);
  1228. X                    if (pre_insert_char)
  1229. X                        tputs(pre_insert_char, ONE_LINE,
  1230. X                           append_to_output_string);
  1231. X                    output_string[output_string_length++] =
  1232. X                        e->current_input_char + '@';
  1233. X                } else if (e->current_input_char == 127) {
  1234. X                    output_string[output_string_length++] = '^';
  1235. X                    if (post_insert_char)
  1236. X                        tputs(post_insert_char, ONE_LINE,
  1237. X                           append_to_output_string);
  1238. X                    if (pre_insert_char)
  1239. X                        tputs(pre_insert_char, ONE_LINE,
  1240. X                           append_to_output_string);
  1241. X                    output_string[output_string_length++] = '?';
  1242. X                } else
  1243. X                    output_string[output_string_length++] =
  1244. X                        e->current_input_char;
  1245. X
  1246. X                if (post_insert_char)
  1247. X                    tputs(post_insert_char, ONE_LINE, append_to_output_string);
  1248. X            }
  1249. X
  1250. X            if (enter_insert_mode)
  1251. X                tputs(exit_insert_mode, ONE_LINE, append_to_output_string);
  1252. X        } else {
  1253. X            for (count = e->universal_argument; count; --count)
  1254. X                display_char_into_output_string(e->current_input_char);
  1255. X            num_to_back_up =
  1256. X                display_string_into_output_string(e->dot);
  1257. X            for (count = num_to_back_up; count; --count)
  1258. X                tputs(cursor_left, ONE_LINE, append_to_output_string);
  1259. X        }
  1260. X    }
  1261. X
  1262. X    strcpy(temp_str, e->dot);
  1263. X    for (count = e->universal_argument; count; --count)
  1264. X        *(e->dot++) = e->current_input_char;
  1265. X    strcpy(e->dot, temp_str);
  1266. X    if (e->mark > old_dot)
  1267. X        e->mark += (e->dot - old_dot);
  1268. X    write(1, output_string, output_string_length);
  1269. X
  1270. X    e->universal_argument = 1;
  1271. X    return OK;
  1272. X}
  1273. X
  1274. X
  1275. Xrun_program_connected_to_standard_tty(cmd)
  1276. X    char           *cmd;
  1277. X{
  1278. X
  1279. X    int             status;
  1280. X    void        (*sig)();
  1281. X
  1282. X    ioctl(0, TIOCGETP, &new_stdin);
  1283. X    ioctl(0, TIOCSETP, &old_stdin);
  1284. X    printf("Now running \"%s\"\r\n", cmd);
  1285. X    sig=signal(SIGCHLD,SIG_DFL); 
  1286. X    status = system(cmd);
  1287. X    signal(SIGCHLD,sig); 
  1288. X    printf("Finished running \"%s\"\r\n", cmd);
  1289. X    ioctl(0, TIOCSETP, &new_stdin);
  1290. X    write(1, "Continue: ", 10);
  1291. X    return status;
  1292. X}
  1293. X
  1294. X
  1295. Xquietly_run_program_connected_to_standard_tty(cmd)
  1296. X    char           *cmd;
  1297. X{
  1298. X
  1299. X    int             status;
  1300. X    void        (*sig)();
  1301. X    
  1302. X    ioctl(0, TIOCGETP, &new_stdin);
  1303. X    ioctl(0, TIOCSETP, &old_stdin);
  1304. X    sig=signal(SIGCHLD,SIG_DFL); 
  1305. X    status = system(cmd);
  1306. X    signal(SIGCHLD,sig); 
  1307. X    ioctl(0, TIOCSETP, &new_stdin);
  1308. X    return status;
  1309. X}
  1310. X
  1311. X
  1312. X
  1313. Xint 
  1314. Xuppercase_word(e)
  1315. X    ED_STRUCT      *e;
  1316. X{
  1317. X
  1318. X    char           *ch, *cb;
  1319. X
  1320. X    cb = e->current_buffer;
  1321. X    ch = e->dot;
  1322. X
  1323. X    if (ch != cb)        /* not at beginning of buffer */
  1324. X        while ((ch >= cb) && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  1325. X            ch--;    /* search backwards until in a word */
  1326. X
  1327. X    while ((ch >= cb) && (isalnum(*ch) || (*ch == '-') || (*ch == '_')))
  1328. X        ch--;        /* find first letter in word */
  1329. X
  1330. X    while (isalnum(*++ch) || (*ch == '-') || (*ch == '_'))
  1331. X        if ((*ch >= 'a') && (*ch <= 'z'))
  1332. X            *ch -= 32;    /* uppercase all lowers */
  1333. X
  1334. X    erase_current_edit_line(e);
  1335. X    draw_current_edit_line(e);
  1336. X    return OK;
  1337. X}
  1338. X
  1339. Xint 
  1340. Xlowercase_word(e)
  1341. X    ED_STRUCT      *e;
  1342. X{
  1343. X
  1344. X    char           *ch, *cb;
  1345. X
  1346. X    cb = e->current_buffer;
  1347. X    ch = e->dot;
  1348. X
  1349. X    if (ch != cb)        /* not at beginning of buffer */
  1350. X        while ((ch >= cb) && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  1351. X            ch--;    /* search backwards until in a word */
  1352. X
  1353. X    while ((ch >= cb) && (isalnum(*ch) || (*ch == '-') || (*ch == '_')))
  1354. X        ch--;        /* find first letter in word */
  1355. X
  1356. X    while (isalnum(*++ch) || (*ch == '-') || (*ch == '_'))
  1357. X        if ((*ch >= 'A') && (*ch <= 'Z'))
  1358. X            *ch += 32;    /* lowercase all uppers */
  1359. X
  1360. X    erase_current_edit_line(e);
  1361. X    draw_current_edit_line(e);
  1362. X    return OK;
  1363. X}
  1364. X
  1365. X
  1366. Xint 
  1367. Xcapitalize_word(e)
  1368. X    ED_STRUCT      *e;
  1369. X{
  1370. X
  1371. X    char           *ch, *cb;
  1372. X    int             subword_flag = 0;
  1373. X
  1374. X    cb = e->current_buffer;
  1375. X    ch = e->dot;
  1376. X
  1377. X    if (ch != cb)        /* not at beginning of buffer */
  1378. X        while ((ch >= cb) && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  1379. X            ch--;    /* search backwards until in a word */
  1380. X
  1381. X    while ((ch >= cb) && (isalnum(*ch) || (*ch == '-') || (*ch == '_')))
  1382. X        ch--;        /* find first letter in word */
  1383. X
  1384. X    if ((*++ch >= 'a') && (*ch <= 'z'))
  1385. X        *ch -= 32;    /* uppercase first letter */
  1386. X
  1387. X    while (isalnum(*++ch) || (*ch == '-') || (*ch == '_'))
  1388. X        if (!isalnum(*ch))
  1389. X            subword_flag = 1;    /* next char starts subword */
  1390. X        else if (subword_flag) {
  1391. X            subword_flag = 0;
  1392. X            if ((*ch >= 'a') && (*ch <= 'z'))
  1393. X                *ch -= 32;    /* uppercase first letter */
  1394. X        } else if ((*ch >= 'A') && (*ch <= 'Z'))
  1395. X            *ch += 32;    /* lowercase subsequent letters */
  1396. X
  1397. X    erase_current_edit_line(e);
  1398. X    draw_current_edit_line(e);
  1399. X    return OK;
  1400. X}
  1401. X
  1402. Xint 
  1403. Xul_to_dash_word(e)
  1404. X    ED_STRUCT      *e;
  1405. X{
  1406. X
  1407. X    char           *ch, *cb;
  1408. X
  1409. X    cb = e->current_buffer;
  1410. X    ch = e->dot;
  1411. X
  1412. X    if (ch != cb)        /* not at beginning of buffer */
  1413. X        while ((ch >= cb) && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  1414. X            ch--;    /* search backwards until in a word */
  1415. X
  1416. X    while ((ch >= cb) && (isalnum(*ch) || (*ch == '-') || (*ch == '_')))
  1417. X        ch--;        /* find first letter in word */
  1418. X
  1419. X    while (isalnum(*++ch) || (*ch == '-') || (*ch == '_'))
  1420. X        if (*ch == '_')    /* replace underscores with hyphens */
  1421. X            *ch = '-';
  1422. X
  1423. X    erase_current_edit_line(e);
  1424. X    draw_current_edit_line(e);
  1425. X    return OK;
  1426. X}
  1427. X
  1428. Xint 
  1429. Xdash_to_ul_word(e)
  1430. X    ED_STRUCT      *e;
  1431. X{
  1432. X
  1433. X    char           *ch, *cb;
  1434. X
  1435. X    cb = e->current_buffer;
  1436. X    ch = e->dot;
  1437. X
  1438. X    if (ch != cb)        /* not at beginning of buffer */
  1439. X        while ((ch >= cb) && (!isalnum(*ch)) && (*ch != '-') && (*ch != '_'))
  1440. X            ch--;    /* search backwards until in a word */
  1441. X
  1442. X    while ((ch >= cb) && (isalnum(*ch) || (*ch == '-') || (*ch == '_')))
  1443. X        ch--;        /* find first letter in word */
  1444. X
  1445. X    while (isalnum(*++ch) || (*ch == '-') || (*ch == '_'))
  1446. X        if (*ch == '-')    /* replace hyphens with underscores */
  1447. X            *ch = '_';
  1448. X
  1449. X    erase_current_edit_line(e);
  1450. X    draw_current_edit_line(e);
  1451. X    return OK;
  1452. X}
  1453. X
  1454. X
  1455. X/*
  1456. Xint 
  1457. Xdescribe_bindings(e)
  1458. X    ED_STRUCT      *e;
  1459. X{
  1460. X
  1461. X    char            cmd[256];
  1462. X
  1463. X    erase_current_edit_line(e);
  1464. X    write(1, "One moment. . .", 15);
  1465. X    strcpy(cmd, "/usr/ucb/more ");
  1466. X    strcat(cmd, getenv("HOME"));
  1467. X    strcat(cmd, ".rk.key_map");
  1468. X    quietly_run_program_connected_to_standard_tty(cmd);
  1469. X    write(1, "Continue: ", 10);
  1470. X    draw_current_edit_line(e);
  1471. X    return OK;
  1472. X}
  1473. X*/
  1474. X
  1475. X        
  1476. X
  1477. Xrun_tty_program(e)
  1478. X    ED_STRUCT      *e;
  1479. X{
  1480. X
  1481. X    char            cmd[512];
  1482. X
  1483. X    erase_current_edit_line(e);
  1484. X    e->dot = e->current_buffer;
  1485. X    e->mark = e->current_buffer;
  1486. X    *(e->dot) = '\0';
  1487. X
  1488. X    ioctl(0, TIOCGETP, &new_stdin);
  1489. X    ioctl(0, TIOCSETP, &old_stdin);
  1490. X    strcpy(cmd, "");
  1491. X    printf("Command to run ([RETURN] to cancel): ");
  1492. X    fflush(stdout);
  1493. X    gets(cmd);
  1494. X    if (cmd[0] == '\0') {
  1495. X        printf("Command cancelled.\r\n");
  1496. X        ioctl(0, TIOCSETP, &new_stdin);
  1497. X    } else {
  1498. X        ioctl(0, TIOCSETP, &new_stdin);
  1499. X        run_program_connected_to_standard_tty(cmd);
  1500. X    }
  1501. X
  1502. X    return OK;
  1503. X}
  1504. X
  1505. Xrun_talk(e)
  1506. X    ED_STRUCT      *e;
  1507. X{
  1508. X
  1509. X    char            cmd[256], *who_to;
  1510. X
  1511. X    erase_current_edit_line(e);
  1512. X    e->dot = e->current_buffer;
  1513. X    e->mark = e->current_buffer;
  1514. X    *(e->dot) = '\0';
  1515. X
  1516. X    ioctl(0, TIOCGETP, &new_stdin);
  1517. X    ioctl(0, TIOCSETP, &old_stdin);
  1518. X    strcpy(cmd, "talk ");
  1519. X    who_to = &cmd[5];
  1520. X    printf("Talk to whom ([RETURN] to cancel): ");
  1521. X    fflush(stdout);
  1522. X    gets(who_to);
  1523. X    if (who_to[0] == '\0') {
  1524. X        printf("Talk cancelled.\r\n");
  1525. X        ioctl(0, TIOCSETP, &new_stdin);
  1526. X    } else {
  1527. X        ioctl(0, TIOCSETP, &new_stdin);
  1528. X        run_program_connected_to_standard_tty(cmd);
  1529. X    }
  1530. X
  1531. X    return OK;
  1532. X}
  1533. X
  1534. Xrun_write(e)
  1535. X    ED_STRUCT      *e;
  1536. X{
  1537. X
  1538. X    char            cmd[256], *who_to;
  1539. X
  1540. X    erase_current_edit_line(e);
  1541. X    e->dot = e->current_buffer;
  1542. X    e->mark = e->current_buffer;
  1543. X    *(e->dot) = '\0';
  1544. X
  1545. X    ioctl(0, TIOCGETP, &new_stdin);
  1546. X    ioctl(0, TIOCSETP, &old_stdin);
  1547. X    strcpy(cmd, "write ");
  1548. X    who_to = &cmd[6];
  1549. X    printf("write to whom ([RETURN] to cancel): ");
  1550. X    fflush(stdout);
  1551. X    gets(who_to);
  1552. X    if (who_to[0] == '\0') {
  1553. X        printf("Write cancelled.\r\n");
  1554. X        ioctl(0, TIOCSETP, &new_stdin);
  1555. X    } else {
  1556. X        ioctl(0, TIOCSETP, &new_stdin);
  1557. X        run_program_connected_to_standard_tty(cmd);
  1558. X    }
  1559. X
  1560. X    return OK;
  1561. X}
  1562. X
  1563. Xrun_pp(e)
  1564. X    ED_STRUCT      *e;
  1565. X{                /* JJD 9-86 */
  1566. X
  1567. X    char            cmd[256], *who_to;
  1568. X
  1569. X    erase_current_edit_line(e);
  1570. X    e->dot = e->current_buffer;
  1571. X    e->mark = e->current_buffer;
  1572. X    *(e->dot) = '\0';
  1573. X
  1574. X    ioctl(0, TIOCGETP, &new_stdin);
  1575. X    ioctl(0, TIOCSETP, &old_stdin);
  1576. X    strcpy(cmd, "pp ");
  1577. X    who_to = &cmd[3];
  1578. X    printf("pp what file ([RETURN] to cancel): ");
  1579. X    fflush(stdout);
  1580. X    gets(who_to);
  1581. X    if (who_to[0] == '\0') {
  1582. X        printf("pp cancelled.\r\n");
  1583. X        ioctl(0, TIOCSETP, &new_stdin);
  1584. X    } else {
  1585. X        ioctl(0, TIOCSETP, &new_stdin);
  1586. X        run_program_connected_to_standard_tty(cmd);
  1587. X    }
  1588. X
  1589. X    return OK;
  1590. X}
  1591. X
  1592. Xrun_mesg(e)
  1593. X    ED_STRUCT      *e;
  1594. X{
  1595. X
  1596. X    char            cmd[256], *on_or_off;
  1597. X
  1598. X    erase_current_edit_line(e);
  1599. X    e->dot = e->current_buffer;
  1600. X    e->mark = e->current_buffer;
  1601. X    *(e->dot) = '\0';
  1602. X
  1603. X    ioctl(0, TIOCGETP, &new_stdin);
  1604. X    ioctl(0, TIOCSETP, &old_stdin);
  1605. X    strcpy(cmd, "mesg ");
  1606. X    on_or_off = &cmd[5];
  1607. X    printf("Do you want \"mesg y\" or \"mesg n\" ");
  1608. X    printf("(type y or n and press [RETURN]): ");
  1609. X    fflush(stdout);
  1610. X    gets(on_or_off);
  1611. X    if (!strncmp(on_or_off, "on", 2))
  1612. X        strcpy(on_or_off, "y");
  1613. X    else if (!strncmp(on_or_off, "off", 3))
  1614. X        strcpy(on_or_off, "n");
  1615. X    else if (*on_or_off == 'y' || *on_or_off == 'n')
  1616. X        on_or_off[1] = '\0';
  1617. X    else if (on_or_off[0] == '\0') {
  1618. X        printf("Mesg cancelled.\r\n");
  1619. X        ioctl(0, TIOCSETP, &new_stdin);
  1620. X        return OK;
  1621. X    } else {
  1622. X        printf("Mesg cancelled because you didn't respond with y or n.\r\n");
  1623. X        ioctl(0, TIOCSETP, &new_stdin);
  1624. X        return OK;
  1625. X    }
  1626. X
  1627. X    ioctl(0, TIOCSETP, &new_stdin);
  1628. X    run_program_connected_to_standard_tty(cmd);
  1629. X    return OK;
  1630. X}
  1631. X
  1632. Xint describe_arguments(e)
  1633. X    ED_STRUCT      *e;
  1634. X{
  1635. X    extern num_buffers;
  1636. X    extern  char silent;
  1637. X    extern  char login;
  1638. X    extern    max_len;
  1639. X    extern    max_eol;
  1640. X    extern char *zero_freq_file;
  1641. X    extern char *prime_file;
  1642. X    extern char *key_file;
  1643. X
  1644. X
  1645. X    printf("\r\nCurrent Command Line Argument Values:\r\n");
  1646. X    printf("    -b (Number of buffers)  = %d\r\n", num_buffers);
  1647. X    printf("    -e (End of Line length)    = %d\r\n",max_eol);
  1648. X    printf("    -f (Maximum Frequency)    = %d\r\n",max_freq);
  1649. X    printf("    -i (Inline Length)    = %d\r\n",max_len);
  1650. X    printf("    -k (Key Bindings File)    = \"%s\"\r\n",key_file);
  1651. X    printf("    -n (Nodes to allocate)    = %d\r\n",max_nodes);
  1652. X    printf("    -o (Order of model)    = %d\r\n",maxk);
  1653. X    printf("    -p (Prime File)        = \"%s\"\r\n",prime_file);
  1654. X    printf("    -s (Maximum to prime)    = %d\r\n",maxprime);
  1655. X    printf("    -z (Zero Frequency File)= \"%s\"\r\n",zero_freq_file);
  1656. X    printf("    -A (add_space_mode)    = %s\r\n",add_space_mode?"TRUE":"FALSE");
  1657. X    printf("    -E (eol_only_mode)    = %s\r\n",eol_only_mode?"TRUE":"FALSE");
  1658. X    printf("    -L (eol_longer_mode)    = %s\r\n",eol_longer_mode?"TRUE":"FALSE");
  1659. X    printf("    -N (nl_truncate_mode)    = %s\r\n",nl_truncate_mode?"TRUE":"FALSE");
  1660. X    printf("    -P (pred_mode)        = %s\r\n",pred_mode?"TRUE":"FALSE");
  1661. X    printf("    -S (show_eol_mode)    = %s\r\n",show_eol_mode?"TRUE":"FALSE");
  1662. X    printf("    -g (login shell)    = %s\r\n",login?"TRUE":"FALSE");
  1663. X    printf("    -l (lisp_mode)        = %s\r\n",lisp_mode?"TRUE":"FALSE");
  1664. X    printf("    -m (silent startup)    = %s\r\n",silent?"TRUE":"FALSE");
  1665. X    write(1, "Continue: ", 10);
  1666. X    draw_current_edit_line(e);
  1667. X    return OK;
  1668. X}
  1669. END_OF_FILE
  1670. if test 35838 -ne `wc -c <'functions.c'`; then
  1671.     echo shar: \"'functions.c'\" unpacked with wrong size!
  1672. fi
  1673. # end of 'functions.c'
  1674. fi
  1675. echo shar: End of archive 4 \(of 4\).
  1676. cp /dev/null ark4isdone
  1677. MISSING=""
  1678. for I in 1 2 3 4 ; do
  1679.     if test ! -f ark${I}isdone ; then
  1680.     MISSING="${MISSING} ${I}"
  1681.     fi
  1682. done
  1683. if test "${MISSING}" = "" ; then
  1684.     echo You have unpacked all 4 archives.
  1685.     rm -f ark[1-9]isdone
  1686. else
  1687.     echo You still need to unpack the following archives:
  1688.     echo "        " ${MISSING}
  1689. fi
  1690. ##  End of shell archive.
  1691. exit 0
  1692.  
  1693.